<template>
  <div class="container">
    <el-dialog
      title="题目预览"
      :visible="flag"
      width="60%"
      :before-close="handleClose"
    >
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="grid-content bg-purple">
            【题型】:{{ obj.questionType | questionTypeFilter(questionType) }}
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">【编号】:{{ obj.id }}</div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">
            【难度】:{{ obj.difficulty | difficultyFilter(difficulty) }}
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">【标签】:{{ obj.tags }}</div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">
            【学科】:{{ obj.subjectName }}
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">
            【目录】:{{ obj.directoryName }}
          </div>
        </el-col>
        <el-col :span="6">
          <div class="grid-content bg-purple">【方向】:{{ obj.direction }}</div>
        </el-col>
      </el-row>

      <hr />
      <div class="tigan">
        <div class="grid-content bg-purple">【题干】:</div>
      </div>
      <!-- 题目 -->
      <p class="question" v-html="obj.question"></p>
      <!-- 题目类型 -->

      <div v-if="!(obj.questionType === '3')" class="choice">
        <div>
          {{ obj.questionType | questionTypeFilter(questionType) }}
          选项:(以下选中的选项为正确答案)
        </div>

        <!-- 单选 -->

        <div v-if="obj.questionType === '1'" class="radio">
          <el-radio-group v-model="radio">
            <div class="checkbox" v-for="item in obj.options" :key="item.id">
              <el-radio :label="item.title"></el-radio>
            </div>
          </el-radio-group>
        </div>
        <!-- 多选 -->
        <div v-else class="check">
          <el-checkbox-group v-model="obj.options">
            <div class="checkbox" v-for="item in obj.options" :key="item.id">
              <el-checkbox
                :label="item.title"
                :checked="item.isRight === 1"
              ></el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
      </div>
      <hr />
      <!-- 参考答案视频 -->
      <div>
        【参考答案】：
        <el-button type="danger" @click="isShow = true">视频答案预览</el-button>
        <div>
          <video
            v-if="isShow"
            class="video"
            :src="obj.videoURL"
            autoplay
            controls
            width="400px"
            height="300px"
          ></video>
        </div>
      </div>
      <hr />
      <!-- 答案解析 -->
      <div>
        【答案解析】：
        <div v-html="obj.answer" style="display:inline-block"></div>
      </div>
      <hr />
      <!-- 题目备注 -->
      <div>
        【题目备注】：
        <div v-html="obj.remarks" style="display:inline-block"></div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleClose">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail as subjectsDetail } from '@/api/hmmm/subjects'
import { detail as directorysDetail } from '@/api/hmmm/directorys'
import { detail } from '@/api/hmmm/questions'
import { questionType, difficulty } from '@/api/hmmm/constants'

export default {
  name: 'QuestionsPreview',
  props: {
    // 开关弹窗信号
    flag: {
      type: Boolean,
      default: false
    },
    // 查看的题目id
    data: {
      type: Object,
      default: function() {
        return {}
      }
    }
  },
  data() {
    return {
      isShow: false,
      radio: '',
      questionType,
      difficulty,
      obj: {},
      objSubjects: {}
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    async handleClose() {
      this.$emit('update:flag', false)
    },
    async getDetail() {
      const { data } = await detail(this.data)
      this.obj = data
      this.radio = data.options.filter(item => item.isRight === 1)[0].title
      const {
        data: { subjectName }
      } = await subjectsDetail({
        id: this.obj.subjectID
      })
      this.obj.subjectName = subjectName

      const {
        data: { directoryName }
      } = await directorysDetail({
        id: this.obj.catalogID
      })
      this.obj.directoryName = directoryName
    }
  }
}
</script>

<style scoped lang="scss">
.checkbox {
  margin: 10px 0;
}
.question {
  color: blue;
}

.grid-content {
  height: 30px;
  line-height: 30px;
}
</style>
